<template>
  <div>
    <s-table
      ref="table"
      :rowKey="(record) => record.id"
      :columns="columns"
      :data="loadData"
      class="user_management_table"
    >
      <span slot="name" slot-scope="text,record">
        <a @click="routerPath(record.id)">{{record.name}}</a>
      </span>
    </s-table>
  </div>
</template>

<script>
import { STable } from '@/components'
import { classList } from '@/api/class'
export default {
  name: 'teachClass',
  components: {
    STable
  },
  created() {},
  props: {
    id: null
  },
  data() {
    return {
      value: 2,
      columns: [
        {
          title: '班级名称',
          dataIndex: 'name',
          width: 150,
          fixed: 'left',
          align: 'center',
          scopedSlots: { customRender: 'name' }
        },
        {
          title: '关联课程',
          dataIndex: 'course_name',
          align: 'center'
        },
        {
          title: '人数',
          dataIndex: 'student_num',
          align: 'center'
        }
      ],
      queryParam: {
        school_id: this.$store.state.user.school,
        teacher_id: this.id
      },
      loadData: parameter => {
        if (this.id) {
          return classList(Object.assign(parameter, this.queryParam))
            .then(res => {
              return res
            })
            .catch(err => {
              this.$message.error(err.data.message||'获取数据失败，请刷新页面或稍后再试')
            })
        } else {
          return
        }
      }
    }
  },
  methods: {
    routerPath(e) {
      this.$router.push({ name: 'class_info', query: { id: e } })
    }
  }
}
</script>

<style lang="less" scoped>
</style>